unit uVideoCaptuer;

interface
uses
  Windows, SysUtils;

type
  TVideoCaptuer = class
  private
    FIns: Integer;
  public
    constructor Create();
    destructor Destroy(); override;
    procedure SetDrawHWNDEx(AHWND: Integer);
    procedure SetURLEx(AURL: string);

    procedure UseDrawTickEx(AUseTick: Boolean);
    procedure Start();
    procedure Stop();
    procedure Show(AShow: Boolean);
    procedure SetAutoReconnect(AAutoReconnect: Boolean);
    procedure SetAudioMute(AMute: Boolean);
    procedure SetAnalyseCallBack(pFun: Pointer; AContext: Integer);
    procedure SetVideoCallBack(AFun: Pointer; AContext: Integer);
    procedure SetAudioCallBack(AFun: Pointer; AContext: Integer);

    function StartEncoderEx(AFileName: PAnsiChar): Integer;
    procedure StopEncoderEx();
  end;

implementation

const
  SimpleVideoViewDLL = 'SimpleVideoView.dll';

function SimpleVideoView_Create(): Integer;
cdecl; external SimpleVideoViewDLL;

procedure SimpleVideoView_Delete(Instance: Integer);
cdecl; external SimpleVideoViewDLL;

procedure SetURL(Instance: Integer; AURL: PAnsiChar);
cdecl; external SimpleVideoViewDLL;

procedure SetDrawHWND(Instance: Integer; AHWND: Integer);
cdecl; external SimpleVideoViewDLL;

procedure StartCaptuer(Instance: Integer);
cdecl; external SimpleVideoViewDLL;

procedure StopCaptuer(Instance: Integer);
cdecl; external SimpleVideoViewDLL;

procedure ShowVideo(Instance: Integer; AShow: Boolean);
cdecl; external SimpleVideoViewDLL;

procedure UseDrawTick(Instance: Integer; AUse: Boolean);
cdecl; external SimpleVideoViewDLL;

procedure AutoReconnect(Instance: Integer; AAutoReconnect: Boolean);
cdecl; external SimpleVideoViewDLL;

procedure AudioMute(Instance: Integer; AMute: Boolean);
cdecl; external SimpleVideoViewDLL;

procedure AnalyseCallBack(Instance: Integer; AFun: Pointer; AContext: Integer);
cdecl; external SimpleVideoViewDLL;

procedure OnVideoCallBack(Instance: Integer; AFun: Pointer; AContext: Integer);
cdecl; external SimpleVideoViewDLL;

procedure OnAudioCallBack(Instance: Integer; AFun: Pointer; AContext: Integer);
cdecl; external SimpleVideoViewDLL;

function StartEncoder(Instance: Integer; AFileName: PAnsiChar): Integer;
cdecl; external SimpleVideoViewDLL;

procedure StopEncoder(Instance: Integer);
cdecl; external SimpleVideoViewDLL;


{ TVideoCapture }

constructor TVideoCaptuer.Create;
begin
  FIns := SimpleVideoView_Create();
end;

destructor TVideoCaptuer.Destroy;
begin
  SimpleVideoView_Delete(FIns);
  inherited;
end;

procedure TVideoCaptuer.SetAnalyseCallBack(pFun: Pointer; AContext: Integer);
begin
  AnalyseCallBack(FIns, pFun, AContext);
end;

procedure TVideoCaptuer.SetAudioCallBack(AFun: Pointer; AContext: Integer);
begin
  OnAudioCallBack(FIns, AFun, AContext);
end;

procedure TVideoCaptuer.SetAudioMute(AMute: Boolean);
begin
  AudioMute(FIns, AMute);
end;

procedure TVideoCaptuer.SetAutoReconnect(AAutoReconnect: Boolean);
begin
  AutoReconnect(FIns, AAutoReconnect);
end;

procedure TVideoCaptuer.SetDrawHWNDEx(AHWND: Integer);
begin
  SetDrawHWND(FIns, AHWND);
end;

procedure TVideoCaptuer.SetURLEx(AURL: string);
begin
  SetURL(FIns, PAnsiChar(AURL));
end;

procedure TVideoCaptuer.SetVideoCallBack(AFun: Pointer; AContext: Integer);
begin
  OnVideoCallBack(FIns, AFun, AContext);
end;

procedure TVideoCaptuer.Show(AShow: Boolean);
begin
  ShowVideo(FIns, AShow);
end;

procedure TVideoCaptuer.Start;
begin
  StartCaptuer(FIns);
end;

function TVideoCaptuer.StartEncoderEx(AFileName: PAnsiChar): Integer;
begin
  Result := StartEncoder(FIns, AFileName);
end;

procedure TVideoCaptuer.Stop;
begin
  StopCaptuer(FIns);
end;

procedure TVideoCaptuer.StopEncoderEx;
begin
  StopEncoder(FIns);
end;

procedure TVideoCaptuer.UseDrawTickEx(AUseTick: Boolean);
begin
  UseDrawTick(FIns, AUseTick);
end;

end.
